package com.siwei.mes.service.erp.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.erp.Contractrelation;
import com.siwei.mes.mapper.erp.ContractrelationMapper;
import com.siwei.mes.service.erp.ContractrelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * (Contractrelation)表服务实现类
 *
 * @author linzi
 * @since 2024-09-24 20:07:56
 */
@Service
public class ContractrelationServiceImpl implements ContractrelationService {
    @Resource
    private ContractrelationMapper contractrelationMapper;

    @Override
    public PageInfo<Contractrelation> getPage(PageQuery<Contractrelation, Contractrelation> query) {
        Contractrelation searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> contractrelationMapper.getList(searchParam));
    }

    @Override
    public Contractrelation loadById(Long id) {
        return contractrelationMapper.loadById(id);
    }

    @Override
    public List<Contractrelation> getAll(Contractrelation entity) {
        return contractrelationMapper.getList(entity);
    }

    @Override
    public Map<Integer, Contractrelation> getContractrelationMap(Set<Integer> frwdList) {
        Map<Integer, Contractrelation> contractrelationMap = new HashMap<>();
        if (frwdList.isEmpty()) {
            return contractrelationMap;
        }
        List<Contractrelation> list = contractrelationMapper.selectByFrwdList(frwdList);
        for (Contractrelation contractrelation : list) {
            contractrelationMap.put(contractrelation.getFrwd(), contractrelation);
        }
        return contractrelationMap;
    }
}
